let randStrSeed = 0;


/**
 * @description: 消息头
 * @param {string} sender 发送者
 * @param {string} serverName 服务器名称
 * @return {string} 消息头
 */
function msgHeader(sender, serverName){
  return (serverName == undefined ? '' :`§r§b[${serverName}]`) + `§r<${sender}>§r`;
}

//随机字符串
/**
 * @description: 随机字符串
 * @return {string} 随机字符串
 */
function randStr() {
  randStrSeed ++;
  let arr_str = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
  return String(`${Date.now()}${randNum(100, 999)}`).match(/./g).map(v => (Number(v) % 2 == 0) ? arr_str[Number(v)].toUpperCase() : arr_str[Number(v)]).join('') + randStrSeed;
}

/**
 * @description: 随机数
 * @param {number} min 最小值
 * @param {number} max 最大值
 * @return {number} 随机数
 */
function randNum(min = 0, max = 255) {
  return Math.floor(Math.random() * max) + min;
}

/**
 * @description: sleep
 * @param {number} time 等待时间(ms)
 * @return {Promise} Promise
 */
async function sleep(time) {
    return new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve();
    }, time);
    });
}

const { v4: uuidv4 } = require('uuid');

module.exports = {
    msgHeader,
    randStr,
    uuidv4,
    sleep
};    